﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Collections.Generic;

namespace HoaDon
{
	public partial class DSHoaDon : System.Web.UI.Page
	{
		private string sql = "";
		protected void Page_Load(object sender, EventArgs e)
		{
			if (Session["NgayBD"] != null)
			{
				DateTime date = DateTime.Parse(Session["NgayBD"].ToString());
				sql += "and Ngay_ct >='" + date.ToString("yyyyMMdd") + "'  ";
			}
			if (Session["NgayKT"] != null)
			{
				DateTime date = DateTime.Parse(Session["NgayKT"].ToString());
				sql += "and Ngay_ct <='" + date.ToString("yyyyMMdd") + "'";
			}

			if (Session["btKhuVuc"] != null)
			{
				if (Session["btKhuVuc"].ToString() != "All")
					if (Session["btBan"].ToString() != "AllB")
					{
						sql += " AND FK_VvID = '" + Session["btBan"].ToString() + "'";
					}
					else
					{
						sql += " AND FK_VvID IN (SELECT vvID FROM dmvv WHERE dmvv.FK_DatabaseID = '" + Session["FK_DatabaseID"].ToString() + "' AND dmvv.FK_NhvvID = '" + Session["btKhuVuc"].ToString() + "')";
					}
			}
			if (Session["HTToanBo"] != null)
				if (Session["HTToanBo"].ToString().Equals("1"))
					sql += " AND Status = '0'";

			DataTable ds = new DataTable();
			ds = SqlEXEC.GetData(Session["strConn"].ToString(), "SELECT * FROM vph81 WHERE FK_DatabaseID = '" + Session["FK_DatabaseID"] + "' AND Status='1' " + sql + " ORDER BY Ngay_Ct");

			gdxdshoadon.DataSource = ds;
			gdxdshoadon.DataBind();
			gdxdshoadon.CssClass = "GridViewInvoice";

		}

		protected void btXoa_Click(object sender, EventArgs ap)
		{
			Button bt = (Button)sender;
			SqlEXEC.ExecCommand(Session["strConn"].ToString(), "EXEC [fs_DeleteHDA] '" + bt.CommandArgument + "', '" + Session["FK_DatabaseID"].ToString() + "', '1'");

			//   Response.Redirect("~\\DSHoaDon.aspx");
		}

		protected void btXem_Click(object sender, EventArgs ap)
		{

		}
	}
}
